﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef OBJECTBROWSER_H
#define OBJECTBROWSER_H

#include <QFrame>
#include <memory>
#include <QString>
#include <QVBoxLayout>

/// 本文件是界面实现的辅助类，不包含GDMP API的演示内容

class QLabel;
class QPushButton;
class QEvent;
class QKeyEvent;

namespace Sample
{
    class CPropertyItem;
    class CInstancePropertyWidget;

    /*!
    *@class CPropertyWidget
    *@brief 属性面板窗口
    *
    */
    class CObjectBrowserWidget : public QFrame
    {
        Q_OBJECT
    public:
        /*!
        * @brief                                                 构造函数
        */
        explicit CObjectBrowserWidget(QWidget* pParent = NULL);
        /*!
        * @brief                                                 析构函数
        */
        virtual ~CObjectBrowserWidget();

        virtual bool eventFilter(QObject *object, QEvent *event) override;

    public:
        /*!
        * @brief      返回属性实例子窗口
        * @return     CInstancePropertyWidget *
        */
        CInstancePropertyWidget *GetComponentInstancePropertyWidget() const { return m_upInstaceWidget.get(); }

        protected slots:
        /*!
        *@brief       编辑修改属性触发的事件
        *@param [in] int groupIndex
        *@param [in] int propertyIndex
        *@return void
        */
        virtual void OnPropertyValueChanged(int groupIndex, int propertyIndex);

        /*!
        * @brief      应用按钮点击回调
        * @return     void
        */
        virtual void OnApply();

        /*!
        * @brief      当下拉列表收起,检查光标离开事件
        * @return     void
        */
        virtual void OnCheckLeaveEvent(QObject* obj);
    Q_SIGNALS:
        void mouseLeave();
        void DropDownListIndexChange(int groupIndex, int propertyIndex);

    protected:
        virtual void keyPressEvent(QKeyEvent *event) override;
        virtual void leaveEvent(QEvent *event) override;
        void setApplyButtonText(const QString& text);

        // 判断是否有属性修改发生
        bool IsPropertyValueChanged()const;

    private:
        void InitWidget();//初始化整体界面
        void InitInstanceWidget();//初始化instance
        void InitApplyButton();//初始化applybutton
        bool IsAlphaKeys(int nChar); // 判断输入键是否为字母

    private:
        std::unique_ptr<QVBoxLayout>              m_upMainLayout;   //主布局
        std::unique_ptr<CInstancePropertyWidget>  m_upInstaceWidget;//添加构件实例
        std::unique_ptr<QPushButton>              m_upApplyButton;  //应用按钮
        std::unique_ptr<QHBoxLayout>              m_upButtonLayout; //按钮布局
        bool                                      m_isHotKeyPressed;//快捷键是否被按下
    };
}

#endif

